package com.dmall.scf.action

import com.dmall.scf.SparkAction
import com.dmall.scf.dto.SupplierRunFieldValue
import org.apache.spark.sql.{DataFrame, SaveMode, SparkSession}

/**
 * @descrption
 * scf-spark
 * @author wangxuexing
 * @date 2019/12/27
 */
object TestAction extends SparkAction[SupplierRunFieldValue]{
  val CLASS_NAME = this.getClass.getSimpleName().filter(!_.equals('$'))

  /**
   * 处理
   * @param spark
   * @return
   */
  override def action(spark: SparkSession, args: Array[String]): DataFrame = {
    val date = "2019-12-01"
    val sql = s"""SELECT 1 company_id,
                         b.company_id supplier_id,
                         '${date}' AS syn_date,
                         39 field_id,
                         sum(a.fafangje) field_value
                    FROM wumart2dmall.wm_ods_jrbl_loan_dkzhxx a
                    JOIN wumart2dmall.wm_ods_cx_supplier_card_info b ON a.gshkahao = b.card_code
                    AND b.audit_status = '2'
                    WHERE to_date(a.gxinshij) BETWEEN date_sub('${date}',180) AND date_sub('${date}',1)
                    GROUP BY b.company_id"""
      spark.sql(sql)
  }

  /**
   * 保存mode及表名
   * @return
   */
  override def saveTable: (SaveMode, String) = (SaveMode.Append, "scfc_supplier_run_field_value")
}
